<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-demo__hzincomecode}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">

        <el-form-item>
          <el-input v-model="dataForm.incomeCode" placeholder="激活码" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.isUse" :placeholder="$t('hzIncomeCode.isUse')" clearable>
            <el-option :label="$t('hzIncomeCode.isUse0')" :value="0"></el-option>
            <el-option :label="$t('hzIncomeCode.isUse1')" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button  type="primary"  @click="gen()">生成</el-button>
        </el-form-item>

      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="incomeCode" label="激活码" header-align="center" align="center"></el-table-column>
        <el-table-column prop="isUse" label="是否使用" header-align="center" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.isUse === 1" size="small" type="danger">{{ $t('hzIncomeCode.isUse1') }}</el-tag>
            <el-tag v-else size="small" type="green">{{ $t('hzIncomeCode.isUse0') }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="days" label="有效期" header-align="center" align="center"></el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/hz/incomecode/page',
        getDataListIsPage: true,
        exportURL: '/demo/hzincomecode/export',
        deleteURL: '/demo/hzincomecode',
        gen: 'hz/incomecode/gen',
        deleteIsBatch: true

      },
      dataForm: {
          incomeCode: '',
          isUse:''
      }
    }
  },
  components: {
  },
  methods: {
      gen() {
          this.$http.get(
              this.mixinViewModuleOptions.gen
          ).then(({data: res}) => {
              if (res.code !== 0) {
                  return this.$message.error(res.msg)
              }
              this.query()
              return this.$message.ok('生成成功')
          }).catch(() => {
              this.dataListLoading = false
          })
      }
  }
}
</script>
